package net.wzw.exception;

import lombok.Data;
import net.wzw.enums.BizCodes;

/**
 * @className: BizException
 * @author: wzw
 * @date: 2024-08-12 18:31
 * @Version: 1.0
 * @description: 统一异常处理类
 */
@Data
public class BizException extends RuntimeException{


    /**
     * 默认错误码
     */
    private static final int DEFAULT_ERROR_CODE = -1;

    /**
     * 异常code码
     */
    private int code;

    /**
     * 异常消息
     */
    private String message;

    /**
     * 根据 code、message 返回异常信息
     * @param code
     * @param message
    */
    public BizException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
    * 根据 BizCode 返回异常信息
    */
    public BizException(BizCodes codes) {
        super(codes.getMessage());
        this.code = codes.getCode();
        this.message = codes.getMessage();
    }

    /**
     * 根据errMsg 返回异常信息
     * **/
    public BizException(String errorMsg){

        super(errorMsg);
        this.code = DEFAULT_ERROR_CODE;
        this.message = errorMsg;

    }
}
